package cz.data.domain.elasticsearch.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import cz.data.common.annotation.DataInner;
import cz.data.common.support.db.driver.DataOperation;
import cz.data.domain.elasticsearch.service.ElasticsearchOperationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = {"ES表数据操作API"})
@RestController
public class ElasticsearchOperationController {

    @Resource
    ElasticsearchOperationService service;

    @DataInner
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "数据-ID查询详情")
    @PostMapping("/api/driver/elasticsearch/getDataById")
    public JSONObject getDataById(@RequestBody @Valid DataOperation operation) {
        return service.getDataById(operation);
    }

    @DataInner
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "数据-分页查询")
    @PostMapping("/api/driver/elasticsearch/getPageData")
    public IPage<JSONObject> getPageData(@RequestBody @Valid DataOperation operation) {
        return service.getPageData(operation);
    }

    @DataInner
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "数据-新增")
    @PostMapping("/api/driver/elasticsearch/insertData")
    public Boolean insertData(@RequestBody @Valid DataOperation operation) {
        return service.insertData(operation);
    }

    @DataInner
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "数据-修改")
    @PostMapping("/api/driver/elasticsearch/updateData")
    public Boolean updateData(@RequestBody @Valid DataOperation operation) {
        return service.updateData(operation);
    }

    @DataInner
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "数据-删除")
    @PostMapping("/api/driver/elasticsearch/removeData")
    public Boolean removeData(@RequestBody @Valid DataOperation operation) {
        return service.removeData(operation);
    }
}
